
#include "../include/algorithm.h"

#include "stdio.h"
#include "stdlib.h"
#include "time.h"

//0 ~ 100, percent
static bool is_probability(int prob);


static bool is_probability(int prob)
{
    int value = (rand()/(RAND_MAX + 1.0)) * 100;

    if (value <= prob)
    {
        return true;
    }
    else
    {
        return false;
    }
}

int alg_data_generate_positive(int data[], int size, int max)
{
    srand((int)time(0));

    for (int i = 0; i < size; i++)
    {
        data[i] = max * (rand()/(1.0 + RAND_MAX));
    }

    return 0;
}

int alg_data_generate_mixed(int data[], int size, int max)
{
    srand((int)time(0));

    for (int i = 0; i < size; i++)
    {
        int value = (rand()/(RAND_MAX + 1.0)) * max;
        //printf("rand: %d\n", value);

        //positive 20%
        if (is_probability(20))
        {
            value = -value;
        }

        data[i] = value;
    }

    return 0;
}

int alg_data_print(const int data[], int size)
{
    printf("\n");

    for (int i = 0; i < size; i++)
    {
        printf("data[%d] = %d\n", i, data[i]);
    }

    return 0;
}

